import hashlib
import json
import time

import requests


class GeTuiConfig:
    appkey = 'EN7s9YbNH99oLifEsD6Fu2'
    mastersecret = 'liFpi0VU5w7fbTLr665QB2'
    appId = 'XyjU7yXC5B8Rp1Bwqt1i87'
    baseUrl = 'https://ido.getui.com/openapi/' + appId


# 获取SHA256加密字符串
def get_sha256(s):
    sha256 = hashlib.sha256()
    sha256.update(s.encode('utf-8'))
    return sha256.hexdigest()


# MD5加密
def get_md5(s):
    md5 = hashlib.md5()
    md5.update(s.encode('utf-8'))
    return md5.hexdigest()


# 鉴权api
def authApi():
    # 获取时间戳
    timestamp = int(time.time() * 1000)
    sign = get_sha256(GeTuiConfig.appkey + str(timestamp) + GeTuiConfig.mastersecret)
    url = GeTuiConfig.baseUrl + '/auth'
    headers = {
        'Content-Type': 'application/json;charset=UTF-8',
        "Accept": "application/json;charset=utf-8"
    }
    data = {
        'sign': sign,
        'appkey': GeTuiConfig.appkey,
        'timestamp': timestamp
    }
    apiResult = requests.post(url=url, headers=headers, data=json.dumps(data))
    print(apiResult.json())


# authApi()

md5 = get_md5('15131142161')
print(md5)